Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JSON Support #83

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add JSON Support #83

wants to merge 1 commit into from

Conversation

lsmith77
Copy link

@lsmith77 lsmith77 commented May 20, 2021

fix for #82

note I am not so expierienced with developing for laravel .. it seems to work ok on a quick check.
I need to add tests. aside from this there are some "taste" things to decide .. like using the ternary syntax inside the Version class or if the call to config() should be "cached" in case multiple versionable models are handled in one request.

@lsmith77 lsmith77 force-pushed the json-support branch 2 times, most recently from c2f4eff to 1d6b29d Compare May 22, 2021 09:28
@codecov-commenter
Copy link

codecov-commenter commented May 22, 2021

Codecov Report

Merging #83 (046814a) into master (043b311) will decrease coverage by 16.25%.
The diff coverage is 14.28%.

❗ Current head 046814a differs from pull request most recent head 599fa0c. Consider uploading reports for the commit 599fa0c to get more accurate results
Impacted file tree graph

@@              Coverage Diff              @@
##             master      #83       +/-   ##
=============================================
- Coverage     98.31%   82.06%   -16.26%     
- Complexity       47       56        +9     
=============================================
  Files             3        4        +1     
  Lines           119      145       +26     
=============================================
+ Hits            117      119        +2     
- Misses            2       26       +24     
Impacted Files Coverage Δ
...rc/Mpociot/Versionable/Console/ConvertEncoding.php 0.00% <0.00%> (ø)
.../Mpociot/Versionable/Providers/ServiceProvider.php 100.00% <100.00%> (ø)
src/Mpociot/Versionable/Version.php 94.11% <100.00%> (ø)
src/Mpociot/Versionable/VersionableTrait.php 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 043b311...599fa0c. Read the comment docs.

@lsmith77
Copy link
Author

@nonoesp any feedback here? thx

@nonoesp
Copy link
Collaborator

nonoesp commented May 28, 2021

Hey, @lsmith77 — I'll try to take a look at this soon (and hopefully test it).

Thanks for the work!

@nonoesp
Copy link
Collaborator

nonoesp commented Jun 15, 2021

Hi, @lsmith77 - I have little time to review and test this.

I'd really appreciate if you could describe the steps I should follow to test this pull request and verify everything works?

🙏

@lsmith77
Copy link
Author

I stilll owe this PR tests.

but fundamentally you have to make sure Mpociot\Versionable\Providers\ServiceProvider::class is registered, that you set in the config the encoding to 'encoding' => 'json', and then run php artisan versionable:convert-encoding to convert from serialize to json` encoding.

@lsmith77
Copy link
Author

I would appreciate advice on how to best test this. f.e. should I use Config::set() in the tests?

@lsmith77
Copy link
Author

lsmith77 commented Jul 1, 2021

I am also wondering if instead or in addition to the command, there should be a migration?

$versionedHiddenFields = $this->versionedHiddenFields ?? [];
$this->makeVisible($versionedHiddenFields);
$version->model_data = serialize($this->attributesToArray());
$version->model_data = $this->getEncoding() ? json_encode($this->attributesToArray()) : serialize($this->attributesToArray());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey! Shouldn't this be $version->model_data = $this->getEncoding() == 'json' ? json_encode($this->attributesToArray()) : serialize($this->attributesToArray());?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed! .. goes to show that this PR needs tests

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it does! I was testing manually yesterday and it doesn't seem to quite work with my site.

@nonoesp nonoesp changed the title WIP add json support WIP Add JSON Support Jul 13, 2021
@lsmith77
Copy link
Author

@nonoesp I think I fixed the bug you encountered, however still didn't have time to figure out how to add tests and generate an efficient migration script. hopefully this week I will manage to do it.

@lsmith77 lsmith77 force-pushed the json-support branch 3 times, most recently from 8c29cd1 to 599fa0c Compare July 25, 2021 09:37
@lsmith77 lsmith77 changed the title WIP Add JSON Support Add JSON Support Jul 25, 2021
@lsmith77
Copy link
Author

@nonoesp I hope this is now ready to be merged.

I added a very simple test case and also documented the process to create a migration with lazy loading (which however requires laravel 8).

@lsmith77 lsmith77 closed this Aug 5, 2021
@lsmith77 lsmith77 reopened this Aug 5, 2021
@nonoesp
Copy link
Collaborator

nonoesp commented Aug 5, 2021

Hi, @lsmith77 - I'll be taking a look at this!

@lsmith77
Copy link
Author

lsmith77 commented Sep 8, 2021

ping?

@nonoesp
Copy link
Collaborator

nonoesp commented Sep 13, 2021

Thanks for the reminder!

@nonoesp
Copy link
Collaborator

nonoesp commented Dec 16, 2021

Hi @lsmith77 can you resolve the conflicts?

@lsmith77
Copy link
Author

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants